$(function() {
	$('#tt').edatagrid({
		onLoadSuccess : function(data) {
			//$(".datagrid-header-check").html("");
			if (data) {
				$.each(data.rows, function(index, item) {
					if (item.isChecked == 1) {
						$('#tt').datagrid('checkRow', index);
					}
				});
			}
		},
		onCheck : function(index,row){
			arr = [];
			arr.push(row.apkId);
			saveApk(arr);
		},
		onUncheck : function(index,row){
			arr = [];
			arr.push(row.apkId);
			delApk(arr);
		},
		onSelectAll : function(rows){
			arr = [];
			$.each(rows, function(index, item) {
				arr.push(item.apkId);
			});
			saveApk(arr);
		},
		onUnselectAll : function(rows){
			arr = [];
			$.each(rows, function(index, item) {
				arr.push(item.apkId);
			});
			delApk(arr);
		}
	})
});

function saveApk (arr){
	$.ajax({
		headers: {
			'Accept': 'application/json',
			'Content-Type': 'application/json'
		},
		url:'/brushConfig/saveApk?brushId='+$('#brushId').val(),
		type:'POST',
		data: JSON.stringify(arr),
		async: true,
		dataType: "json"
	})
}

function delApk (arr){
	$.ajax({
		headers: {
			'Accept': 'application/json',
			'Content-Type': 'application/json'
		},
		url : '/brushConfig/delApk?brushId='+$('#brushId').val(),
		type:'POST',
		data: JSON.stringify(arr),
		async: true,
		dataType: "json"
	})
}

function doSearch() {
	$('#tt').datagrid('load', {
		brushId: $('#brushId').val(),
		baseId: $('#baseId').val(),
		apkName: $('#apkName').val()
	});
}